package co.edu.usbcali.egrapico.vista.ambient;

import co.edu.usbcali.egrapico.vista.tools.MethodList;

public class PanelObject extends javax.swing.JInternalFrame implements java.io.Serializable {

    private javax.swing.ImageIcon Iobjeto1, Iobjeto2, Iobjeto3, Iobjeto4, Iobjeto5;
    private javax.swing.JLabel l2;
    private javax.swing.JLabel l4;
    private String nameParent;
    LabelSender l1;//restricciones de recepcion
    LabelForward l5;
    LabelObjectProperties l3;

    /**
     * Creates a new instance of PanelDragAndDrop
     */
    public PanelObject(PanelObject ob) {
        this();
        nameParent = ob.getNameParent();
        setNameObject(nameParent);
        l1.setNameParent(nameParent);
        l1.getFrame().loadPresedent(ob.getSender().getFrame());
        l1.Ladicionar();
        l5.setNameParent(nameParent);
        l5.Ladicionar();
        l3.setNameParent(ob.getPropertiesFrame().getNameParent());
        l3.setTitlePanel(ob.getPropertiesFrame().getTitlePanel());
        l3.getFrame().loadProperties(ob.getPropertiesFrame().getFrame());
        l3.Ladicionar();
    }

    public PanelObject() {
        super();
        setClosable(true);
        Iobjeto1 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/mailboxEmpty.gif"));
        Iobjeto2 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/listener.gif"));
        Iobjeto3 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/object.gif"));
        Iobjeto4 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/transmitter.gif"));
        Iobjeto5 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/mailboxEmpty.gif"));
        nameParent = "";
        l1 = new LabelSender();
        l1.setIcon(Iobjeto1);
        l5 = new LabelForward();
        l5.setIcon(Iobjeto5);
        l2 = new javax.swing.JLabel();
        l2.setIcon(Iobjeto2);
        l3 = new LabelObjectProperties();
        l3.setIcon(Iobjeto3);
        l4 = new javax.swing.JLabel();
        l4.setIcon(Iobjeto4);
        getContentPane().setLayout(new java.awt.FlowLayout());//new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.X_AXIS));
        setBackground(new java.awt.Color(255, 255, 255));
        setFrameIcon(null);
        getContentPane().add(l1);
        getContentPane().add(l2);
        getContentPane().add(l3);
        getContentPane().add(l4);
        getContentPane().add(l5);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setBounds(160, 110, 340, 110);
        setVisible(true);
        l1.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                L1MouseClicked(evt);
            }
        });
        l5.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                L5MouseClicked(evt);
            }
        });
        l3.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                L3MouseClicked(evt);
            }
        });

    }

    public void addMyListenerToLPane() {
        l1.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                L1MouseClicked(evt);
            }
        });
        l5.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                L5MouseClicked(evt);
            }
        });
        l3.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                L3MouseClicked(evt);
            }
        });

    }

    private void L1MouseClicked(java.awt.event.MouseEvent evt) {
        if (evt.getClickCount() == 2) {
            if (l1.isCreate() == false) {
                l1.setNameParent(getNameParent());
                l1.Ladicionar();
            } else {
                l1.mostrarPanel();
            }
        }
    }

    private void L5MouseClicked(java.awt.event.MouseEvent evt) {
        if (evt.getClickCount() == 2) {
            if (l5.isCreate() == false) {
                l5.setNameParent(getNameParent());
                l5.Ladicionar();
            } else {
                l5.mostrarPanel();
            }
        }
    }

    private void L3MouseClicked(java.awt.event.MouseEvent evt) {
        if (evt.getClickCount() == 2) {
            if (l3.isCreate() == false) {
                l3.setNameParent(getNameParent());
                l3.Ladicionar();
            } else {
                l3.mostrarPanel();
            }
        }
    }

    //metodos para el frame 
    public LabelForward getForward() {
        return l5;
    }

    public LabelSender getSender() {
        return l1;
    }

    public LabelObjectProperties getPropertiesFrame() {
        return l3;
    }

    public int getMethodCountL() {
        return l3.getMethodCountObj();
    }

    public MethodList getMethodL(int n) {
        return l3.getMethod(n);
    }

    public void setNameParent(String name) {
        nameParent = name;
    }

    public String getNameParent() {
        return nameParent;
    }

    public void setNameObject(String i) {
        nameParent = i;
        setTitle(i);
        l3.setNameObject(i);
    }

    public boolean isCreateObject() {
        return l3.getFrame().iscreateObject();
    }

    public void mostrarPrecedent() {
        if (l1.isCreate() == false) {
            l1.setNameParent(getNameParent());
            l1.Ladicionar();
        } else {
            l1.mostrarPanel();
        }
    }

    public void mostrarConsecuent() {
        if (l5.isCreate() == false) {
            l5.setNameParent(getNameParent());
            l5.Ladicionar();
        } else {
            l5.mostrarPanel();
        }

    }

    public void mostrarProperties() {
        if (l3.isCreate() == false) {
            l3.setNameParent(getNameParent());
            l3.Ladicionar();
        } else {
            l3.mostrarPanel();
        }

    }
}
